<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6" :xs="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>个人信息</span>
          </div>
          <div>
            <div class="diy-text-sm diy-leading-10"><svg-icon icon-class="user" />&nbsp;个人头像</div>
            <div class="text-center">
              <userAvatar :user="user" />
            </div>
            <!-- <div class="diy-text-sm diy-leading-10"><svg-icon icon-class="system" />&nbsp;系统LOGO</div>
            <div class="diy-h-16 diy-mb-2.5 diy-relative" style="background:#d6d6d6;display: flex;align-items: center;justify-content: center;">
              <img :src="logoText" class="systemLogo diy-cursor-pointer" @click="handleUpload">
            </div>
            <div class="diy-text-xs diy-text-gray"><i class="el-icon-info diy-mr-1.5"></i>最佳尺寸：280像素x70像素</div> -->
            <el-upload action="#" :http-request="requestUpload" :show-file-list="false" :before-upload="beforeUpload" ref="uploadLogo" v-show="false">
              <el-button size="small">
                选择
                <i class="el-icon-upload el-icon--right"></i>
              </el-button>
              <div slot="tip" class="el-upload__tip">最佳尺寸：280像素x70像素</div>
            </el-upload>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <svg-icon icon-class="user" />用户名称
                <div class="pull-right">{{ user.username }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="phone" />手机号码
                <div class="pull-right">{{ user.phoneNumber }}</div>
              </li>
              <!-- <li class="list-group-item">
                <svg-icon icon-class="email" />用户邮箱
                <div class="pull-right">{{ user.email }}</div>
              </li> -->
              <li class="list-group-item">
                <svg-icon icon-class="tree" />所属部门
                <div class="pull-right" v-if="user.sysDeptStr">{{ user.sysDeptStr }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="peoples" />所属角色
                <div class="pull-right">{{ roleGroup }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="date" />创建日期
                <div class="pull-right">{{ user.createTime }}</div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18" :xs="24">
        <el-card>
          <div slot="header" class="clearfix">
            <span>基本资料</span>
          </div>
          <el-tabs v-model="activeTab">
            <el-tab-pane label="基本资料" name="userinfo">
              <userInfo :user="user" />
            </el-tab-pane>
            <el-tab-pane label="修改密码" name="resetPwd">
              <resetPwd />
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import userAvatar from "./components/userAvatar.vue";
  import userInfo from "./components/userInfo";
  import resetPwd from "./components/resetPwd";
  import { getUserInfo } from "@/api/permission/user";
  export default {
    name: "Profile",
    components: { userAvatar, userInfo, resetPwd },
    data() {
      return {
        user: {},
        roleGroup: {},
        postGroup: {},
        activeTab: "userinfo",
        logoText: ''
      };
    },
    async created() {
      this.getUser();
      // const systemLogo = this.$store.state.user.systemLogo;
      // if(systemLogo != null && systemLogo !='null' && systemLogo!=''){
      //   this.logoText = systemLogo;
      // }

    },
    methods: {
      getUser() {//获取个人信息
        getUserInfo().then(response => {
          let data = response.data || {}
          this.user = data
          this.roleGroup = data.roles.toString();
          this.postGroup = data.sysDeptStr;
        });
      },
      //点击触发el-upload
      handleUpload(){
        this.$refs["uploadLogo"].$refs["upload-inner"].handleClick();
      },
      // 覆盖默认的上传行为
      requestUpload() {
      },
      //系统logo上传
      beforeUpload(file) {
        if (file.type.indexOf("image/") == -1) {
          this.$message.error('文件格式错误，请上传图片类型,如：JPG，PNG后缀的文件。')
        } else {
          let formData = new FormData();
          formData.append("logofile", file);
          uploadSystemlogo(formData).then(response => {
            if (response.code != 200) return;
            //console.log(this.$store)
            //this.$store.dispatch('GetInfo');
            console.log(response.imgUrl)
            this.$store.commit('SET_SYSTEMLOGO', response.imgUrl);
            //console.log(this.$store.state.user.systemLogo);
            this.logoText = response.imgUrl;
            this.$message.success('修改成功')
            setTimeout(()=>{
              location.reload()
            },1000)
          });
        }
      },
    }
  };
</script>

<style scoped>
  .systemLogo{
    width:200px;
    height:50px;
    /* margin-left: -100px;
    margin-top: -25px;
    position:absolute;
    left: 50%;
    top: 50%; */
  }
  .diy-h-16{height: 4rem;}
  .diy-text-gray {
      --tw-text-opacity: 1;
      color: rgba(153,153,153,var(--tw-text-opacity));
  }

  .diy-text-sm {
      font-size: .875rem;
      line-height: 1.25rem;
  }
  .diy-leading-10 {
      line-height: 2.5rem;
  }
  .diy-text-xs {
      font-size: .75rem;
      line-height: 1rem;
  }
  .diy-mb-2\.5 {
      margin-bottom: 0.625rem;
  }
</style>
